/**
 * 问题管理页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：问题管理
     创建日期：2015-12-14
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	questionList();
});

/**
 * 查询问题
 * @returns
 */
var questionList = function(){

	var projectId = $('#q_projectId').val();
	var datas =  {"p":"questionManage","m":"queryQuestionList","projectId":projectId};
	var columnDefine = {"id":"编号","projectId":"项目ID","remark":"备注","title":"问题"};
	
	var formatters={
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-danger\' onclick="openModifyWin();">修改问题</button>&nbsp;&nbsp;';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-info\' onclick="openAnswerWin();">查看选项</button>';
		buttons+='</p>';
	   hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
};

/**
 * 查看答案列表
 * @returns
 */
var openAnswerWin = function(){
	var data = $('#pop_win .data').text();
	var json = eval('('+data+')');
	window.location.href='page?p=page/answerManage&questionId='+json.id;
};

/**
 * 显示修改窗口
 * @returns
 */
var openModifyWin = function(){
	var data = $('#pop_win .data').text();
	var json = eval('('+data+')');
	$('#modifyQuestionWin input').val('');
	$('#modifyQuestionWin .id').val(json.id);
	$('#modifyQuestionWin .projectId').val(json.projectId);
	$('#modifyQuestionWin .title').val(json.title);
	$('#pop_win').modal('hide');
	$('#modifyQuestionWin').modal('show');
};

/**
 * 显示新建窗口
 * @returns
 */
var openNewWin  = function(){
	var projectId = $('#q_projectId').val();
	$('#newQuestionWin input').val('');
	$('#pop_win').modal('hide');
	$('#newQuestionWin').modal('show');
	$('#newQuestionWin .projectId').val(projectId);
};


/**
 * 新建问题
 * @returns
 */
var newQuestion = function(){
	var projectId = $('#newQuestionWin .projectId').val();
	var title = $('#newQuestionWin .title').val();
	var datas = {"p":"questionManage","m":"addQuestion","projectId":projectId,"title":title};
	var json = common.ajaxRequest('service', datas, 'POST');
	
	if( json && json.result == 0 )
    {
		questionList();
		$('#newQuestionWin').modal('hide');
		common.showMsg('info', null , '创建成功!');
    }
	else
	{
		common.showMsg('error', null , '创建失败!');
		return;
	}
};


/**
 * 修改问题
 * @returns
 */
var modifyQuestion = function(){
	var id = $('#modifyQuestionWin .id').val();
	var title = $('#modifyQuestionWin .title').val();
	var datas = {"p":"questionManage","m":"modifyQuestion","id":id,"title":title};
	var json = common.ajaxRequest('service', datas, 'POST');
	
	if( json && json.result == 0 )
	{
		questionList();
		$('#modifyQuestionWin').modal('hide');
		common.showMsg('info', null , '修改成功!');
	}
	else
	{
		common.showMsg('error', null , '修改失败!');
		return;
	}
};